package com.thwj.project.system.controller;

import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.page.TableDataInfo;
import com.thwj.common.enums.BusinessType;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.framework.web.domain.R;
import com.thwj.project.system.domain.SysOss;
import com.thwj.project.system.service.ISysOssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * oss 文件上传Controller
 *
 * @author 可乐
 * @date 2022-03-20
 */
@RestController
@RequestMapping("/system/oss")
//@Api(tags = "后台专用文件上传")
public class SysOssController extends BaseController {
    @Autowired
    private ISysOssService sysOssService;

    /**
     * 查询oss 文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysOss:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOss sysOss) {
        startPage();
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        return getDataTable(list);
    }

    /**
     * 导出oss 文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysOss:export')")
    @Log(title = "oss 文件上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOss sysOss) {
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        ExcelUtil<SysOss> util = new ExcelUtil<SysOss>(SysOss.class);
        util.exportExcel(response, list, "oss 文件上传数据");
    }

    /**
     * 新增oss 文件上传
     */
    @ApiOperation(value = "新增oss 文件上传")
    @PostMapping("/add")
    public R add(@RequestParam("file") MultipartFile file, @RequestParam(value = "size", defaultValue = "0") int size) {
        return R.data(sysOssService.addSysOsss(file, size));
    }

    /**
     * 批量新增oss 文件上传
     */
    @ApiOperation(value = "批量新增oss 文件上传")
    @PostMapping("/addList")
    public R add(@RequestParam("file") MultipartFile[] file, @RequestParam(value = "size", defaultValue = "0") int size) {
        return R.data(sysOssService.insertSysOsss(file, size));
    }

}
